<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Lib_party
{
	private $error = array();

	function __construct()
	{
		$this->ci =& get_instance();

		$this->ci->load->config('party', TRUE);

		$this->ci->load->library('session');
		$this->ci->load->database();
		$this->ci->load->model('party/party_model');

		// Try to autologin
	//	$this->autologin();
	}

function get_list_parties()
  {
    return $this->ci->party_model->get_list_parties();
  }

function get_party_by_id($id)
  {
    return $this->ci->party_model->get_party_by_id((int)$id, TRUE);
  }

function get_list_parties_for_table()
  {
      $partiesList = $this->get_list_parties();
      $partiesListPartial = array();
      foreach($partiesList as $key => $party)
      {
          $partiesListPartial[$key]['id'] = $party->id;
          $partiesListPartial[$key]['name_event'] = $party->name_event;
          $partiesListPartial[$key]['content'] = $party->content;
          $partiesListPartial[$key]['activated_party'] = $party->activated_party;
          $partiesListPartial[$key]['activated_inscription'] = $party->activated_inscription;
          $partiesListPartial[$key]['picture_menu'] = $party->picture_menu;

          //update link :
          $url = site_url('admin/updateParty/'.$party->id);
          $partiesListPartial[$key]['update_link'] = '<a class="update_party" href="'.$url.'">Modifier</a>';
          
          
          //delete link :
          $url = site_url('admin/deleteParty/'.$party->id);
          $partiesListPartial[$key]['delete_link'] = '<a class="delete_party" href="'.$url.'">Supprimer</a>';
      }

      return $partiesListPartial;
  }
  
function modify_party($id, $name_event, $content)
    {

    $party_id = (int)$id;

		if (!is_null($party = $this->ci->party_model->get_party_by_id($party_id))) { // party existant
			$this->ci->party_model->modify_party($party_id, $name_event, $content);
			return TRUE;
                }
		return FALSE;
	}
	
function create_party($name_event, $content)
	{
			$data = array(
				'name_event'	=> $name_event,
				'content'	=> $content,
				);
		
			if (!is_null($res = $this->ci->party_model->create_party($data))) {
				$data['party_id'] = $res['party_id'];
				return $data;
			}
		
		return NULL;
	}




}
?>
